#include "editorview.h"
#include "application.h"
#include "document.h"
#include "gameObjects/abstractgameobject.h"
#include "editors/editormanager.h"
#include "modes/objecteditormode.h"
#include "globaldata.h"

EditorView::EditorView(Modes::ObjectEditorMode& objectEditorMode, QWidget *parent) :
    QWidget(parent)
	, m_objectEditorMode(objectEditorMode)
{
	connect(Application::instance().globalData(), SIGNAL(currentAnimationFrameChanged(int)),
		this, SLOT(update()));
}

void EditorView::paintEvent(QPaintEvent *)
{
	QPainter painter(this);
	painter.fillRect(rect(), QColor::fromRgb(54, 48, 48));
	m_objectEditorMode.editorManager()->paint(painter);
}

void EditorView::onDocumentChanged( QPointer<Document> doc )
{
	if(doc)
	{
		connect(doc, SIGNAL(objectDataChanged(QPointer<AbstractGameObject>)),
			this, SLOT(update()));
	}
}